package org.example.dormsystem.service.impl;

import org.example.dormsystem.mapper.DormitoryMapper;
import org.example.dormsystem.mapper.StudentMapper;
import org.example.dormsystem.pojo.Dormitory;
import org.example.dormsystem.pojo.Student;
import org.example.dormsystem.service.StudentService;
import org.example.dormsystem.util.Md5Util;
import org.example.dormsystem.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentMapper studentMapper;

    @Autowired
    DormitoryMapper dormitoryMapper;

    @Override
    public Student findStudentByStudentId(Integer studentId) {
        Student student = studentMapper.findStudentByStudentId(studentId);
        return student;
    }

    @Override
    public boolean register(Integer studentId, String studentName) {
        try {
            studentMapper.add(studentId,studentName);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }

    @Override
    public Dormitory findDormIdByStudentId(String dormitoryNumber) {

        Dormitory dormitory = dormitoryMapper.findDormIdByStudentId(dormitoryNumber);

        return dormitory;
    }

    @Override
    public void submitStudent(Student student) {
        studentMapper.submitStudent(student);
    }

    @Override
    public List<Student> findStudentByDormitoryNumber(String dormitoryNumber) {
        List<Student> list = studentMapper.findStudentByDormitoryNumber(dormitoryNumber);
        return list;
    }

    @Override
    public List<Student> getAll() {
        List<Student>list= studentMapper.getAll();
        return list;
    }
}
